//
//  ByViewLoginProtocolAgreement.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/10/20.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByViewLoginProtocolAgreement.h"

@implementation ByViewLoginProtocolAgreement
{
    UIButton     *_toggleButton;        // 是否按钮
    UILabel      *_noteLabel;           // 注释
    UIButton     *_protocolButton;      // 去看协议
}
- (instancetype)init {
    
    if (self = [super init]) {
        
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    
    // 按钮
    _toggleButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_toggleButton setImage:[UIImage imageNamed:@"unselected"] forState:UIControlStateNormal];
    [_toggleButton setImage:[UIImage imageNamed:@"selected"] forState:UIControlStateSelected];
    [_toggleButton addTarget:self action:@selector(toggle:) forControlEvents:UIControlEventTouchUpInside];
    [_toggleButton setImageEdgeInsets:UIEdgeInsetsMake(3, 3, 3, 3)];
    [self addSubview:_toggleButton];
    [_toggleButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.height.equalTo(self);
        make.width.equalTo(_toggleButton.mas_height);
        make.top.equalTo(self);
    }];
    
    // 注释
    _noteLabel = [[UILabel alloc] init];
    _noteLabel.adjustsFontSizeToFitWidth = true;
    _noteLabel.numberOfLines = 1;
    _noteLabel.text = @"登录即表示同意";
    _noteLabel.font = FONT(14);
    _noteLabel.textAlignment = NSTextAlignmentLeft;
    _noteLabel.textColor = [UIColor blackColor];
    [self addSubview:_noteLabel];
    [_noteLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_toggleButton.mas_right).offset(5);
        make.top.equalTo(self);
        make.height.equalTo(self);
        make.width.mas_equalTo([_noteLabel.text getSizeOfString:14].width + 5);
    }];
    
    // 看协议按钮
    _protocolButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _protocolButton.titleLabel.font = FONT(14);
    [_protocolButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [_protocolButton setTitle:@"《用户协议》" forState:UIControlStateNormal];
    [_protocolButton setTitleColor:BY_RED_COLOR forState:UIControlStateNormal];
    [_protocolButton addTarget:self action:@selector(lookProtocol) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_protocolButton];
    [_protocolButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_noteLabel.mas_right);
        make.top.equalTo(self);
        make.height.equalTo(self);
        make.right.equalTo(self);
    }];
}


#pragma mark - 点击事件
// 同意与否
- (void)toggle:(UIButton *)button {
    
    button.selected = !button.selected;
    
    self.agree = button.selected;
}
// 去看协议
- (void)lookProtocol {
    
    [ByCoreToolAlert showOnlyText:@"去看协议"];
}

@end
